

class Solution {
public:
    vector<string> ret;

    vector<string> binaryTreePaths(TreeNode* root) {
        string path;
        dfs(root,path);
        return ret;
    }
    void dfs(TreeNode*root,string path)
    {
        if(root==nullptr) return;
        if(root->left==nullptr&&root->right==nullptr)
        {
            path+=to_string(root->val);
            ret.push_back(path);            
            return;
        }
        path+=to_string(root->val)+"->";
        if(root->left) dfs(root->left,path);
       if(root->right) dfs(root->right,path);
    }
};